var webpack = require('webpack')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var getHtmlConfig = function (name,title) {
	return{
		template:'./src/view/'+name+'.html',
		filename : "view/"+name+'.html',
		title : title,
		inject : true,
		hash : true,
		chunks:['common',name]
	}
}

var config = {
	entry:{
		'common':['./src/page/common/index.js'],
		'index':['./src/page/index/index.js'],
		'login':['./src/page/login/index.js'],
		'user-register':['./src/page/register/index.js'],
		'order-list' : ['./src/page/order-list/index.js'],
        'order-confirm' : ['./src/page/order-confirm/index.js']
	},
	output:{
		path : __dirname+'/dist/',
		filename:'js/[name].js'
	},
	resolve : {
		alias : {
			'@' : __dirname+'/src'
		}
	},
	module:{
		rules:[
			{
				test:/\.js$/,
				exclude:/(node_modules)/,
				use:[{loader:"babel-loader"}]
			},
			{
				test:/\.css$/,
				use:['style-loader','css-loader']
			},
			{
				test:/\.(gif|png|jpg|ttf)\??.*$/,
				use:[{loader:"url-loader"}]
			}
			,{
				test:/\.string$/,
				use:[{loader:"html-loader"}]
			}
		],
		loaders:[
			{test:/\.js$/,loader:'babel-loader',query:{presets:['es2015']}},
			{test: /\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/, loader: 'url-loader?limit=100&name=resource/[name].[ext]' },
			{test:/\.css$/,loader:"style-loader!css-loader"}
			
		]
	},
	plugins:[
		//new ExtractTextPlugin("css.css"),
		new HtmlWebpackPlugin({
			template:'./src/view/index.html',
			filename : 'index.html',
			title : 'index',
			inject : true,
			hash : true,
			chunks:['common','index']
		}),
		new HtmlWebpackPlugin({
			template:'./src/view/login.html',
			filename : 'view/login.html',
			title : 'login',
			inject : true,
			hash : true,
			chunks:['common','login']
		}),
		new HtmlWebpackPlugin(getHtmlConfig('user-register','user-register')),
		new HtmlWebpackPlugin(getHtmlConfig('order-list','order-list')),
		new HtmlWebpackPlugin(getHtmlConfig('order-confirm','order-confirm'))
	],
	node : {
		fs:"empty"
	}
}

module.exports = config;